; hello-os
; TAB = 4

		ORG		0x7c00
		
		JMP		entry
		DB		0x90
		DB		"HELLOIPL"		
		DW		512				
		DB		1				
		DW		1				
		DB		2				
		DW		224				
		DW		2880			
		DB		0xf0			
		DW		9				
		DW		18				
		DW		2				
		DD		0				
		DD		2880			
		DB		0,0,0x29		
		DD		0xffffffff		
		DB		"HELLO-OS   "	
		DB		"FAT12   "		
		RESB	18		

entry:
		; SS = SP = DS = 0
		; init reg
		MOV		AX, 0
		MOV		SS, AX
		MOV		SP, 0x7c00
		MOV		DS, AX
		
		; AH = 0x02, AL = sec num
		; ES:BX = dist buffer addr
		; CH = cylinder, CL = sector
		; DH = head, DL = driver
		; INT 0x13
		MOV		AX, 0x820
		MOV		ES, AX
		MOV		BX, 0
		MOV		CH, 0
		MOV		CL, 2
		MOV		DH, 0
		MOV		DL, 0
		
read_loop:
		MOV		AH, 0x02
		MOV		AL, 0x01
		INT		0x13
		
		CMP		CL, 18
		JE		next_head
		ADD		CL, 1
		MOV		AX, ES
		ADD		AX, 0x20
		MOV		ES, AX
		JMP		read_loop
		
next_head:
		CMP		DH, 1
		JE		next_cylinder
		ADD		DH, 1
		MOV		CL, 1
		MOV		AX, ES
		ADD		AX, 0x20
		MOV		ES, AX
		JMP		read_loop
		
next_cylinder:
		CMP		CH, 9
		JE		fin
		ADD		CH, 1
		MOV		DH, 0
		MOV		CL, 1
		MOV		AX, ES
		ADD		AX, 0x20
		MOV		ES, AX
		JMP		read_loop
		
		; AL = char, AH = 0x0e
		; BX = 15
		; INT 0x10
		; put a char on the console
		MOV		SI, msg
putloop:
		MOV		AL, [SI]
		ADD		SI, 1
		CMP		AL, 0
		JE		fin
		MOV		AH, 0x0e
		MOV		BX, 15
		INT		0x10
		JMP		putloop

fin:
		HLT
		JMP		fin

msg:
		DB		0x0a, 0x0a
		DB		"hello, world"
		DB		0x0a
		DB		0

		RESB	0x7dfe-$
		DB		0x55, 0xaa